<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var weChatDataGrid;
    $(function() {
        weChatDataGrid = $('#weChatDataGrid').datagrid({
        url : '${path}/admin/weChat/dataGrid',
        striped : true,
        rownumbers : true,
        pagination : true,
        idField : 'id',
        sortName : 'id',
        sortOrder : 'desc',
        pageSize : 20,
        pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
        frozenColumns : [ [
            {
                width : '50',
                title : '多选',
                field:'ck',
                checkbox:true 
            }
			,{
           	 	width : '50',
           	 	title : 'id',
           	 	field : 'id',
                sortable: true,
			},{
                width : '90',
                title : '头像',
                field : 'headImgUrl',
                formatter: function (value, row, index) {
                    return "<a href='" + value + "' target='_blank' class='hImgCenter'><img src='" + value + "' height='60px'/></a>";
                }

            }
			,{
           	 	width : '70',
           	 	title : '是否关注',
           	 	field : 'subscribe',
                sortable: true,
                align : 'center',
                ${dic:getBusDictListToCase("WECHAT_SUBSCRIBE")}

			},{
                width : '130',
                title : '微信昵称',
                field : 'nikeName',
                sortable: true,

            }
//			,{
//           	 	width : '70',
//           	 	title : 'unionId',
//           	 	field : 'unionId',
//                  sortable: true,
//			}
//          ,{
//                width : '130',
//                title : '真实姓名',
//                field : 'name',
//                sortable: true,
//
//           }
			,{
           	 	width : '60',
           	 	title : '性别',
           	 	field : 'sex',
                align : 'center',
                sortable: true,
                ${dic:getBusDictListToCase("WECHAT_SEX")}
			}
			,{
           	 	width : '70',
           	 	title : '语言',
           	 	field : 'language',
                align : 'center',
                sortable: true,

			}
			,{
                width : '100',
                title : 'country',
                field : 'country',
                sortable: true,

            },{
           	 	width : '100',
           	 	title : 'province',
           	 	field : 'province',
                sortable: true,
			},{
                width : '100',
                title : 'city',
                field : 'city',
                sortable: true,
            },{
           	 	width : '60',
           	 	title : '组别id',
           	 	field : 'groupId',
                align : 'center',
                sortable: true,
			},{
                width : '250',
                title : 'openId',
                field : 'openId',
                sortable: true,

            },{
                width : '150',
                title : '取关时间',
                field : 'removeDate',
                align : 'center',
                sortable: true,
            }
            ,{
                width : '150',
                title : '关注时间',
                field : 'subscribeTime',
                align : 'center',
                sortable: true,
            }
//            ,{
//           	 	width : '150',
//           	 	title : '修改时间',
//           	 	field : 'updatedTime',
//                align : 'center',
//                sortable: true,
//			}
			,{
                field : 'action',
                title : '操作',
                width : 250,
                formatter : function(value, row, index) {
                    var str = '';
                    <shiro:hasPermission name="/admin/weChat/edit">
                    str += $.formatString('<a href="javascript:void(0)" class="weChat-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="weChatEditFun(\'{0}\');" >编辑</a>', row.id);
                    </shiro:hasPermission>
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="weChat-easyui-linkbutton-location" data-options="plain:true,iconCls:\'fi-target-two icon-green\'" onclick="weChatLocationFun(\'{0}\');" >定位</a>', row.id);

                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="weChat-easyui-linkbutton-sendmsg" data-options="plain:true,iconCls:\'fi-comments icon-yellow\'" onclick="weChatSendMsgFun(\'{0}\');" >发送消息</a>', row.id);

                    <%--<shiro:hasPermission name="/admin/weChat/delete">--%>
                    <%--str += '&nbsp;&nbsp;|&nbsp;&nbsp;';--%>
                    <%--str += $.formatString('<a href="javascript:void(0)" class="weChat-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="weChatDeleteFun(\'{0}\');" >删除</a>', row.id);--%>
                    <%--</shiro:hasPermission>--%>
                    return str;
                }
            }
          ] ],
        singleSelect: false,
        selectOnCheck: true,
        checkOnSelect: true,
        onLoadSuccess:function(data){
            if(data){
                $.each(data.rows, function(index, item){
                    if(item.checked){
                        $('#contentDataGrid').datagrid('checkRow', index);
                    }
                });
            }
            $('.weChat-easyui-linkbutton-edit').linkbutton({text:'编辑'});
            $('.weChat-easyui-linkbutton-location').linkbutton({text:'定位'});
            $('.weChat-easyui-linkbutton-sendmsg').linkbutton({text:'发送消息'});

//            $('.weChat-easyui-linkbutton-del').linkbutton({text:'删除'});
        },
        toolbar : '#weChatToolbar'
    });
});


/**
 * 发送消息
 */
function weChatSendMsgFun(id) {
    progressLoad();
    $.post('${path}/admin/weChat/sendmsg', {id : id}, function(result) {
        if (result.success) {
            parent.$.messager.alert('提示', result.msg, 'info');
            weChatDataGrid.datagrid('reload');
        }
        progressClose();
    }, 'JSON');
}
/**
 * 添加框
 * @param url
 */
function weChatAddFun() {
    parent.$.modalDialog({
        title : '添加',
        width : "800px",
        height : "600px",
        href : '${path}/admin/weChat/addPage',
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = weChatDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#weChatAddForm');
                f.submit();
            }
        } ]
    });
}


/**
 * 定位
 */
function weChatLocationFun(id) {
    parent.$.modalDialog({
        title : '定位',
        width : "80%",
        height : "60%",
        href :  '${path}/admin/weChatLocation/manager?id=' + id,

    });
}

/**
 * 编辑
 */
function weChatEditFun(id) {
    if (id == undefined) {
        var rows = weChatDataGrid.datagrid('getSelections');
        id = rows[0].id;
    } else {
        weChatDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
    }
    parent.$.modalDialog({
        title : '编辑',
        width : "800px",
        height : "600px",
        href :  '${path}/admin/weChat/editPage?id=' + id,
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = weChatDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#weChatEditForm');
                f.submit();
            }
        } ]
    });
}


<%--/**--%>
 <%--* 删除--%>
 <%--*/--%>
 <%--function weChatDeleteFun(id) {--%>
     <%--if (id == undefined) {//点击右键菜单才会触发这个--%>
         <%--var rows = weChatDataGrid.datagrid('getSelections');--%>
         <%--id = rows[0].id;--%>
     <%--} else {//点击操作里面的删除图标会触发这个--%>
         <%--weChatDataGrid.datagrid('unselectAll').datagrid('uncheckAll');--%>
     <%--}--%>
     <%--parent.$.messager.confirm('询问', '您是否要删除当前数据？', function(b) {--%>
         <%--if (b) {--%>
             <%--progressLoad();--%>
             <%--$.post('${path}/admin/weChat/delete', {--%>
                 <%--id : id--%>
             <%--}, function(result) {--%>
                 <%--if (result.success) {--%>
                     <%--parent.$.messager.alert('提示', result.msg, 'info');--%>
                     <%--weChatDataGrid.datagrid('reload');--%>
                 <%--}--%>
                 <%--progressClose();--%>
             <%--}, 'JSON');--%>
         <%--}--%>
     <%--});--%>
<%--}--%>

/**
 * 批量删除
 */
function weChatDeleteIdsFun(){
	var ids = getweChatSelectionsIds();
 	if(ids.length == 0){
 		$.messager.alert('提示','未选中数据!');
 		return ;
 	}
 	$.messager.confirm('确认','确定删除ID为 '+ids+' 的记录,共'+ids.split(",").length+'记录吗？',function(r){
 	    if (r){
 	    	var params = {"ids":ids};
         	$.post("${path}/admin/weChat/deleteIds",params, function(result){
         		result=JSON.parse(result);
     			if(result.success){
     				parent.$.messager.alert('提示', result.msg, 'info');
                    weChatDataGrid.datagrid('reload');
     			}else{
     				$.messager.alert('错误提示',data.msg);
     			}
     		});
 	    }
 	});
}
/**
 * 获得选中的记录
 */
function getweChatSelectionsIds(){
	var itemList = $("#weChatDataGrid");
	var sels = itemList.datagrid("getSelections");
	var ids = [];
	for(var i in sels){
		ids.push(sels[i].id);
	}
	ids = ids.join(",");
	sels.length=0;
	return ids;
}

/**
 * 清除
 */
function weChatCleanFun() {
    $('#weChatSearchForm input').val('');
    weChatDataGrid.datagrid('load', {});
}
/**
 * 搜索
 */
function weChatSearchFun() {
     weChatDataGrid.datagrid('load', $.serializeObject($('#weChatSearchForm')));
}
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'north',border:false" class="lay_box" style="height: 30px; overflow: hidden;background-color: #fff">
        <form id="weChatSearchForm">
            <div class="tab_box">
                <div class="tab_a">
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="weChatSearchFun();">查询</a>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="weChatCleanFun();">清空</a>
                </div>
                <ul class="list">
					<li>
                        <label>openId:</label>
                        <input name="openId" type="text" placeholder="请输入open_id" class="easyui-textbox" data-options="height:29,width:250"/>
                    </li>
					<li>
                        <label>微信昵称:</label>
                        <input name="nikeName" type="text" placeholder="请输入nike_name" class="easyui-textbox" data-options="height:29,width:200"/>
                    </li>
					<li>
                        <label>性别:</label>
                        <select name="sex" class="easyui-combobox" data-options="width:150,height:29,editable:false,panelHeight:'auto'">
                            <option value="">请选择</option>
                            ${dic:getBusDictListToOption('WECHAT_SEX')}
                        </select>
                    </li>
                    <li>
                        <label>是否关注:</label>
                        <select  name="subscribe" class="easyui-combobox" data-options="width:150,height:29,editable:false,panelHeight:'auto'">
                            <option value="">请选择</option>
                            ${dic:getBusDictListToOption('WECHAT_SUBSCRIBE')}
                        </select>
                    </li>
                </ul>
            </div>
        </form>
     </div>
 
    <div data-options="region:'center',border:false">
        <table id="weChatDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="weChatToolbar" style="display: none;">
    <shiro:hasPermission name="/admin/weChat/add">
        <a onclick="weChatAddFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-page-add'">添加</a>
    </shiro:hasPermission>
        <shiro:hasPermission name="/admin/content/deleteIds">
        <a onclick="weChatDeleteIdsFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-x icon-red'">删除</a>
    </shiro:hasPermission>
</div>